{% extends 'myhome/index.html' %}

{% block title %}
<title>结算页面</title>
{% endblock %}
{% block css %}
<link rel="stylesheet" type="text/css" href="/static/myhome/css/global.css">
<link rel="stylesheet" type="text/css" href="/static/myhome/css/app.css">
<script type="text/javascript" src="/static/myhome/js/rem.js"></script>
<script type="text/javascript" src="/static/myhome/js/topNav.js"></script>
<link href="/static/myhome/register/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />

<link href="/static/myhome/register/basic/css/demo.css" rel="stylesheet" type="text/css" />
<link href="/static/myhome/register/css/cartstyle.css" rel="stylesheet" type="text/css" />

<link href="/static/myhome/register/css/jsstyle.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="/static/myhome/register/js/address.js"></script>
{% endblock %}

      
{% block phone %}
{% endblock %}            <!--悬浮搜索框-->

            

{% block cont %}  
<div style="height:80px"></div>   
<div class="concent" >
    <!--地址 -->
    <div class="paycont">
        <div class="address">
            <h3>确认收货地址 </h3>
            <div class="control">
                <div class="tc-btn createAddr theme-login am-btn am-btn-danger">使用新地址</div>
            </div>
            <div class="clear"></div>
            <ul class="addr">
                <div class="per-border"></div>
                {% for i in address %}
                <li addrid="{{i.id}}" class="user-addresslist {% if i.isselect == 1 %}defaultAddr{% endif %}">

                    <div class="address-left">
                        <div class="user DefaultAddr">

                            <span class="buy-address-detail">   
                                <span class="buy-user">{{i.shr}} </span>
                                <span class="buy-phone">{{i.phone}}</span>
                            </span>
                        </div>
                        <div class="default-address DefaultAddr">
                            <span class="buy-line-title buy-line-title-type">收货地址：</span>
                            <span class="buy--address-detail">
                                <span class="province">{{i.sheng}}</span>
                                <span class="city">{{i.shi}}</span>
                                <span class="dist">{{i.zhen_id}}</span>
                                <span class="street">{{i.info}}</span>
                                
                            </span>
                        </div>
                        {% if i.isselect == 1 %}
                        <ins class="deftip">默认地址</ins>
                        {% endif %}
                    </div>
                    <div class="address-right">
                        <a href="/static/myhome/register/person/address.html">
                            <span class="am-icon-angle-right am-icon-lg"></span></a>
                    </div>
                    <div class="clear"></div>

                    <div class="new-addr-btn">
                        <a href="#" class="hidden">设为默认</a>
                        <span class="new-addr-bar hidden">|</span>
                        <a href="#">编辑</a>
                        <span class="new-addr-bar">|</span>
                        <a href="javascript:void(0);" class="del">删除</a>
                    </div>
                </li>
                <div class="per-border"></div>
                {% endfor %}
            </ul>

            <div class="clear"></div>
        </div>
        <!--物流 -->
        <div class="logistics">
            <h3>选择物流方式</h3>
            <ul class="op_express_delivery_hot wl">
                <li data-value="yuantong"  class="OP_LOG_BTN  "><i class="c-gap-right" style="background-position:0px -468px"></i>圆通<span></span></li>
                <li data-value="shentong" class="OP_LOG_BTN  "><i class="c-gap-right" style="background-position:0px -1008px"></i>申通<span></span></li>
                <li data-value="yunda" class="OP_LOG_BTN  "><i class="c-gap-right" style="background-position:0px -576px"></i>韵达<span></span></li>
                <li data-value="zhongtong" class="OP_LOG_BTN op_express_delivery_hot_last "><i class="c-gap-right" style="background-position:0px -324px"></i>中通<span></span></li>
                <li data-value="shunfeng" class="OP_LOG_BTN  op_express_delivery_hot_bottom"><i class="c-gap-right" style="background-position:0px -180px"></i>顺丰<span></span></li>
            </ul>
        </div>
        <div class="clear"></div>

        <!--支付方式-->
        <div class="logistics">
            <h3>选择支付方式</h3>
            <ul class="pay-list">
                <li class="pay card" paytype="card"><img src="/static/myhome/register/images/wangyin.jpg" />银联<span></span></li>
                <li class="pay qq" paytype="wx"><img src="/static/myhome/register/images/weizhifu.jpg" />微信<span></span></li>
                <li class="pay taobao" paytype="zfb"><img src="/static/myhome/register/images/zhifubao.jpg" />支付宝<span></span></li>
            </ul>
        </div>
        <div class="clear"></div>

        <!--订单 -->
        <div class="concent">
            <div id="payTable">
                <h3>确认订单信息</h3>
                <div class="cart-table-th">
                    <div class="wp">

                        <div class="th th-item">
                            <div class="td-inner">商品信息</div>
                        </div>
                        <div class="th th-price">
                            <div class="td-inner">单价</div>
                        </div>
                        <div class="th th-amount">
                            <div class="td-inner">数量</div>
                        </div>
                        <div class="th th-sum">
                            <div class="td-inner">金额</div>
                        </div>
                        <div class="th th-oplist">
                            <div class="td-inner">配送方式</div>
                        </div>

                    </div>
                </div>
                <div class="clear"></div>

                <tr class="item-list">
                    <div class="bundle  bundle-last">

                        <div class="bundle-main">
                            {% for i in data %}
                            <ul class="item-content clearfix">
                                <div class="pay-phone">
                                    <li class="td td-item">
                                        <div class="item-pic">
                                            <a href="#" class="J_MakePoint">
                                                <img src="{{i.gid.pic_url}}" class="itempic J_ItemImg" width="100%"></a>
                                        </div>
                                        <div class="item-info">
                                            <div class="item-basic-info">
                                                <a href="#" class="item-title J_MakePoint" data-point="tbcart.8.11">{{i.gid.title}}</a>
                                            </div>
                                        </div>
                                    </li>
                                    <li class="td td-info">
                                        <div class="item-props">
                                            <span class="sku-line">{{i.gid.info|safe}}</span>
                                            
                                        </div>
                                    </li>
                                    <li class="td td-price">
                                        <div class="item-price price-promo-promo">
                                            <div class="price-content">
                                                <em class="J_Price price-now">{{i.gid.price}}</em>
                                            </div>
                                        </div>
                                    </li>
                                </div>
                                <li class="td td-amount">
                                    <div class="amount-wrapper ">
                                        <div class="item-amount ">
                                            <span class="phone-title">购买数量</span>
                                            <div class="sl">
                                                <!-- <input class="min am-btn" name="" type="button" value="-" /> -->
                                                <input class="text_box" disabled value="{{i.gnum}}" name="" type="text" value="3" style="width:30px;" />
                                                <!-- <input class="add am-btn" name="" type="button" value="+" /> -->
                                            </div>
                                        </div>
                                    </div>
                                </li>
                                <li class="td td-sum">
                                    <div class="td-inner">
                                        {% load tables %}
                                        <em tabindex="0" class="J_ItemSum number total">{% pricexj i.gnum i.gid.price %}</em>
                                        
                                    </div>
                                </li>
                                <li class="td td-oplist">
                                    <div class="td-inner">
                                        <span class="phone-title">配送方式</span>
                                        <div class="pay-logis">
                                            包邮
                                        </div>
                                    </div>
                                </li>

                            </ul>
                            <div class="clear"></div>
                            {% endfor %}

                        </div>
                </tr>
                <div class="clear"></div>
                </div>

                
                </div>
                <div class="clear"></div>
                <div class="pay-total">
            <!--留言-->
                <div class="order-extra">
                    <div class="order-user-info">
                        <div id="holyshit257" class="memo">
                            <label>买家留言：</label>
                            <input type="text" title="选填,对本次交易的说明（建议填写已经和卖家达成一致的说明）" placeholder="选填,建议填写和卖家达成一致的说明" class="memo-input J_MakePoint c2c-text-default memo-close">
                            <div class="msg hidden J-msg">
                                <p class="error">最多输入500个字符</p>
                            </div>
                        </div>
                    </div>

                </div>
                <!--优惠券 -->
                <div class="buy-agio">
                    <li class="td td-coupon">

                        <span class="coupon-title">优惠券</span>
                        <select data-am-selected>
                            <option value="a">
                                <div class="c-price">
                                    <strong>￥8</strong>
                                </div>
                                <div class="c-limit">
                                    【消费满95元可用】
                                </div>
                            </option>
                            <option value="b" selected>
                                <div class="c-price">
                                    <strong>￥3</strong>
                                </div>
                                <div class="c-limit">
                                    【无使用门槛】
                                </div>
                            </option>
                        </select>
                    </li>

                    <li class="td td-bonus">

                        <span class="bonus-title">红包</span>
                        <select data-am-selected>
                            <option value="a">
                                <div class="item-info">
                                    ¥50.00<span>元</span>
                                </div>
                                <div class="item-remainderprice">
                                    <span>还剩</span>10.40<span>元</span>
                                </div>
                            </option>
                            <option value="b" selected>
                                <div class="item-info">
                                    ¥50.00<span>元</span>
                                </div>
                                <div class="item-remainderprice">
                                    <span>还剩</span>50.00<span>元</span>
                                </div>
                            </option>
                        </select>

                    </li>

                </div>
                <div class="clear"></div>
                </div>
                <!--含运费小计 -->
                <div class="buy-point-discharge ">
                    <p class="price g_price ">
                        合计（含运费） <span>¥</span><em class="pay-sum">244.00</em>
                    </p>
                </div>

                <!--信息 -->
                <div class="order-go clearfix">
                    <div class="pay-confirm clearfix">
                        <div class="box">
                            <div tabindex="0" id="holyshit267" class="realPay"><em class="t">实付款：</em>
                                <span class="price g_price ">
                        <span>¥</span> <em class="style-large-bold-red " id="J_ActualFee">244.00</em>
                                </span>
                            </div>
                            {% for i in address %}
                            {% if i.isselect == 1 %}
                            <div id="holyshit268" class="pay-address">

                                <p class="buy-footer-address">
                                    <span class="buy-line-title buy-line-title-type">寄送至：</span>
                                    <span class="buy--address-detail">
                                    <span class="province">{{i.sheng}}</span>
                                    <span class="city">{{i.shi}}</span>
                                    <span class="dist">{{i.xq}}</span>
                                    <span class="street">{{i.info}}</span>
                                    </span>
                                    </span>
                                </p>
                                <p class="buy-footer-address">
                                    <span class="buy-line-title">收货人：</span>
                                    <span class="buy-address-detail">   
                                    <span class="buy-user">{{i.shr}} </span>
                                    <span class="buy-phone">{{i.phone}}</span>
                                    </span>
                                </p>
                            </div>
                            {% endif %}
                            {% endfor %}
                        </div>

                        <div id="holyshit269" class="submitOrder">
                            <div class="go-btn-wrap">
                                <form action="{% url 'myhome_orderinfo' %}" method="POST">
                                    {% csrf_token %}
                                    <input type="hidden" name="cid" value="{{request.GET.cid}}">
                                    <input type="hidden" name="addrid" value="">
                                    <input type="hidden" name="wl" value="">
                                    <input type="hidden" name="paytype" value="">
                                    <a id="J_Go" href="#" class="btn-go" tabindex="0" title="点击此按钮，提交订单">提交订单</a>
                                </form>
                            </div>
                        </div>
                        <div class="clear"></div>

                    </div>
                </div>
            </div>

            <div class="clear"></div>
        </div>
    </div>
    <div class="footer">
        <div class="footer-hd">
            <p>
                <a href="#">恒望科技</a>
                <b>|</b>
                <a href="#">商城首页</a>
                <b>|</b>
                <a href="#">支付宝</a>
                <b>|</b>
                <a href="#">物流</a>
            </p>
        </div>
        <div class="footer-bd">
            <p>
                <a href="#">关于恒望</a>
                <a href="#">合作伙伴</a>
                <a href="#">联系我们</a>
                <a href="#">网站地图</a>
                <em>© 2015-2025 Hengwang.com 版权所有</em>
            </p>
        </div>
    </div>
</div>
<div class="theme-popover-mask"></div>
<div class="theme-popover">

    <!--标题 -->
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add address</small></div>
    </div>
    <hr/>

    <div class="am-u-md-12">
        <form class="am-form am-form-horizontal">

            <div class="am-form-group">
                <label for="user-name" class="am-form-label">收货人</label>
                <div class="am-form-content">
                    <input type="text" id="user-name" placeholder="收货人">
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-phone" class="am-form-label">手机号码</label>
                <div class="am-form-content">
                    <input id="user-phone" placeholder="手机号必填" type="email">
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-phone" class="am-form-label">所在地</label>
                <div class="am-form-content address">
                    
                    <select data-am-selected class="select ">
                        {% for i in citys %}
                        <option value="{{i.id}}">{{i.name}}</option>
                        {% endfor %}
                    </select>

                    <select data-am-selected class="select " name="shi">
                        <option >请选择</option>
                    </select>

                    <select data-am-selected class="select " name="xq">
                        <option >请选择</option>
                    </select>
                   
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-intro" class="am-form-label">详细地址</label>
                <div class="am-form-content">
                    <textarea class="" rows="3" id="user-intro" placeholder="输入详细地址"></textarea>
                    <small>100字以内写出你的详细地址</small>
                </div>
            </div>

            <div class="am-form-group theme-poptit">
                <div class="am-u-sm-9 am-u-sm-push-3">
                    <div class="am-btn am-btn-danger save">保存</div>
                    <div class="am-btn am-btn-danger close">取消</div>
                </div>
            </div>
        </form>
    </div>

</div>

<div class="clear"></div>

            <script type="text/javascript">
                // 选择地址
                $('.addr li').click(function(){
                    var name = $(this).find('.buy-user').text();
                    var phone = $(this).find('.buy-phone').text();
                    var sheng = $(this).find('.province').text();
                    var shi = $(this).find('.city').text();
                    var xq = $(this).find('.dist').text();
                    var info = $(this).find('.street').text();
                    // 写入地址
                    $('.pay-address .buy-user').html(name);
                    $('.pay-address .buy-phone').html(phone);
                    $('.pay-address .province').html(sheng);
                    $('.pay-address .city').html(shi);
                    $('.pay-address .dist').html(xq);
                    $('.pay-address .street').html(info);
                    // 获取addrid属性 给隐藏域
                    $('input[name=addrid]').val($(this).attr('addrid'))
                })
                // 选择物流
                $('.wl li').click(function(){
                    $('input[name=wl]').val($(this).attr('data-value'))
                })
                // 选择支付方式
                $('.pay-list li').click(function(){
                    $('input[name=paytype]').val($(this).attr('paytype'))

                })

                // 发送请求
                $('#J_Go').click(function(){
                    if(!$('input[name=wl]').val()){
                        alert('请选择物流')
                        return 
                    }
                    if(!$('input[name=paytype]').val()){
                        alert('请选择支付方式')
                        return
                    }
                    $(this).parents('form').submit()
                })


                // 设置默认地址
                
                $('input[name=addrid]').val($('.defaultAddr').attr('addrid'))







                var totalprice = 0
                $('.total').each(function(){
                    totalprice+=Number($(this).text())
                })
                // 将总价写入到合计中
                $('.pay-sum').html(totalprice)
                $('#J_ActualFee').html(totalprice)


                // 城级联动
                $('.address').on('click','.select',function(){
                    var id = $(this).val();
                   
                    // 发送ajax请求 /?upid=id
                    $.get('{% url "myhome_citys" %}',{'upid':id},function(data){
                        
                        if(data.length>0){
                            // 判断返回数据的层级 [{},{}] 如果市2级就获取第二个select
                            if(data[0]['level']==2){
                                var sel = $('select[name=shi]')
                            }else if(data[0]['level']==3){
                                var sel = $('select[name=xq]')

                            }
                            var str1=''
                            for(var i=0;i<data.length;i++){
                                str1 += '<option value="'+data[i].id+'">'+data[i].name+'</option>'
                            }
                            // 讲拼接好的数据 写到select
                            sel.html(str1);
                            
                        }
                       
                        
                    })
            })

            // 获取地址 添加
            $('.save').click(function(){
                // 获取素有的信息
                var data = {}
                data.phone= $('#user-phone').val()
                data.name=$('#user-name').val()
                data.citys = $('.address').find('select:eq(2)').val()
                data.info = $('#user-intro').val()
                
                //把获取到的数据 发给后台入库
                $.get('{% url "myhome_saveadd" %}',data,function(data){
                    if(data['error']==1){
                        alert('添加成功');
                        // 成功后关闭谈窗
                        // $('.theme-popover').css('display','none');
                        location.href="{% url 'myhome_order' %}?cid={{request.GET.cid}}"

                    }else{
                        alert('添加失败')
                    }
                })

            })
            $('li').on('click','.del',function(){
                var cid=$(this).parents('li').attr('addrid')
                var el = $(this)
            $.get('{% url "myhome_deladd" %}',{'cid':cid},function(data){
                alert('删除成功')
                // 删除元素节点
                el.parents('li').remove()
            })

        })






</script>
{% endblock %}

